<?php
/**
* @author Tibor Pino (tibor.pino@gmail.com)
* @license released under GNU Public License v. 2
* @copyright Copyright (c) 2007, Tibor Pino
*
*/

App::import('Vendor','texy/compact');

class TexyHelper extends AppHelper
{
    function createMenuBar() {
        $output = '<input type="button" onclick="insertAtCursor(document.commentsAddForm.CommentText, \'**\', \'**\')" value="b"/>
                <input type="button" onclick="insertAtCursor(document.commentsAddForm.CommentText, \'//\', \'//\')"  value="i"/>
                <input type="button" onclick="insertAtCursor(document.commentsAddForm.CommentText, \'/---code\n\', \'\n\\\---\')"  value="code"/>
                <input type="button" onclick="insertAtCursor(document.commentsAddForm.CommentText, \'&quot;'.__("TEXY_URL_NAME",true).'&quot;:\', \'\')"  value="link"/>
                <input type="button" onclick="insertAtCursor(document.commentsAddForm.CommentText, \'&quot;'.__("TEXY_EMAIL_NAME",true).'&quot;:\', \'\')"  value="email"/>
                <input type="button" onclick="insertAtCursor(document.commentsAddForm.CommentText, \'\', \'&nbsp;.{color:red}\')" value="color"/>
                <input type="button" onclick="insertAtCursor(document.commentsAddForm.CommentText, \'\', \'&nbsp;.&lt;&gt;\')" value="center"/>
                <input type="button" onclick="insertAtCursor(document.commentsAddForm.CommentText, \'\', \'&nbsp;.&gt;\')" value="right"/>';

        return $this -> output($output);
    }

    function show($text,$type='article')
    {
        $texy =& new Texy();

        switch($type) {
            case 'article':
                $texy->allowedTags = true;
                $output = $texy -> process($text);
                break;
            case 'comment':
                $texy->allowedClasses = false;
                $texy->allowedTags = false;
                $texy->allowedStyles = array('color','center','a href','code','b','i');
                $output = $texy -> process($text);
                break;
            case 'rss':
                $texy->process($text);
                $output = $texy->toText();
            }

            return $this -> output($output);
        }
    }
    ?>